package com.springboot.hotel.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.springboot.hotel.model.RoomType;
import com.springboot.hotel.model.SysUser;
import com.springboot.hotel.service.RoomTypeService;
import com.springboot.hotel.mapper.RoomTypeMapper;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import java.util.List;

/**
* @author 12641
* @description 针对表【room_type】的数据库操作Service实现
* @createDate 2023-06-15 09:02:48
*/
@Service
public class RoomTypeServiceImpl extends MPJBaseServiceImpl<RoomTypeMapper, RoomType>
    implements RoomTypeService{

    @Override
    public PageInfo<RoomType> list(RoomType roomType, Integer page, Integer limit) {
        // 查询条件
        QueryWrapper<RoomType> wrapper = new QueryWrapper<>();
//        wrapper.select("id","type","price","description","cream_time","update_time","state","is_del");
        if (StringUtils.hasLength(roomType.getType())){
            wrapper.like("type", roomType.getType());
        }
        if (!ObjectUtils.isEmpty(roomType.getPriceMin())){
            // 价格是以分为单位的，所以要乘以100. 大于等于
            wrapper.ge("price", roomType.getPriceMin() * 100);
        }
        if (!ObjectUtils.isEmpty(roomType.getPriceMax())){
            // 价格是以分为单位的，所以要乘以100. 小于等于
            wrapper.le("price", roomType.getPriceMax() * 100);
        }
        wrapper.eq("state", 1);
        wrapper.eq("is_del", 0);
        // 分页
        PageHelper.startPage(page, limit);
        // 查询并封装成 PageInfo 对象
//        List<RoomType> types = getBaseMapper().listSelect(roomType);
        List<RoomType> list = listDeep(wrapper);
//        getBaseMapper().listSelect(roomType);
        PageInfo<RoomType> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public int saveRoomType(RoomType roomType) {
        roomType.setType(roomType.getType());
        roomType.setPrice(roomType.getPrice());
        roomType.setDescription(roomType.getDescription());
        return save(roomType)?1:-1;
    }

    @Override
    public PageInfo<RoomType> selectByIsdel(RoomType roomType, Integer page, Integer limit) {
        // 分页
        PageHelper.startPage(page, limit);
        // 查询条件
        QueryWrapper<RoomType> wrapper = new QueryWrapper<>();
//        查询isdel为true的数据
        wrapper.eq("is_del", true);
        // 查询并封装成 PageInfo 对象
        List<RoomType> roomTypes = getBaseMapper().selectList(wrapper);
        PageInfo<RoomType> pageInfo = new PageInfo<>(roomTypes);
        return pageInfo;
    }
}




